package com.zkingsoft.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.constance.SystemErrorCode;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.ModelUtils;
import com.matrix.core.tools.UUIDUtil;
import com.matrix.core.tools.WebUtil;
import com.zkingsoft.bean.BizCashout;
import com.zkingsoft.common.bean.SysUsers;
import com.zkingsoft.dao.BizCashoutDao;
import com.zkingsoft.service.BizCashoutService;

/**
 * @description service接口实现类(提现表)
 * @author 何明
 * @date 2018-07-17 21:18
 */
@Service
public class  BizCashoutServiceImpl implements  BizCashoutService{

	
	@Autowired
	private BizCashoutDao bizCashoutDao;
	
	
	@Override
	public int add(BizCashout bizCashout){
		// 设置基本字段信息
		SysUsers loginUser = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
		bizCashout.setCreateBy(loginUser.getSuName());
		bizCashout.setUpdateBy(loginUser.getSuName());
		bizCashout.setCasId(UUIDUtil.getRandomID());
		return bizCashoutDao.insert(bizCashout);
		
	}
	
	@Override
	public int batchAdd(List<BizCashout>  bizCashoutList) {
		//这里没有做基本字段的设置，如有需要请自己实现	
		int num = 0;
		int c = 10000;
		int size = bizCashoutList.size()/c + 1;
		for(int i=0; i<size; i++) {
			int begin = i*c;
			int end = (i+1)*c;
			end = end >= bizCashoutList.size() ? bizCashoutList.size() : end;
			List<BizCashout> insertList = bizCashoutList.subList(begin, end);
			num += bizCashoutDao.batchInsert(insertList);
		}
		return num;
		
	}
	
	
   	
    @Override
	public int modifyByMap(BizCashout oldBizCashout
	,BizCashout newBizCashout){
	
		Map<String, Object> modifyMap = null;
		try {
			if (!ModelUtils.isModified(oldBizCashout, newBizCashout)) {
				return MatrixConstance.DML_SUCCESSS;
			}
			modifyMap = ModelUtils.comparePojo2Map(oldBizCashout, newBizCashout);
		} catch (Exception e) {
			throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, newBizCashout);
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("casId", oldBizCashout.getCasId());
			bizCashoutDao.updateByMap(modifyMap);
		}
		return MatrixConstance.DML_SUCCESSS;
	}
	
	@Override
	public int modifyByModel(BizCashout bizCashout){
	
		return bizCashoutDao.updateByModel(bizCashout);
	
	}
	
	
	
	@Override
	public int remove(List<String> list){
	
		return bizCashoutDao.deleteByIds(list);
	
	}

	@Override
	public int removeById(String casId){
	
		return bizCashoutDao.deleteById(casId);
	
	}
	
	@Override
	public int removeByModel(BizCashout bizCashout){
	
		return bizCashoutDao.deleteByModel(bizCashout);
	
	}
	
	
	@Override
	public List<BizCashout> findInPage(BizCashout bizCashout,  PaginationVO pageVo){
	
		return bizCashoutDao.selectInPage(bizCashout , pageVo);
	
	}
	
	@Override
	public List<BizCashout> findByModel(BizCashout bizCashout){
	
		return bizCashoutDao.selectByModel(bizCashout);
	
	}
	
	@Override
	public int  findTotal(BizCashout bizCashout){
	
		return bizCashoutDao.selectTotalRecord(bizCashout);
	
	}
	
	@Override
	public BizCashout  findById(String casId){
	
		return bizCashoutDao.selectById(casId);
	
	}

   	
	
	
}